package com.ruoyi.admin.service.impl;

import com.ruoyi.admin.domain.RewardExchangeVO;
import com.ruoyi.admin.mapper.RewardExchangeMapper;
import com.ruoyi.admin.mapper.RewardMapper;
import com.ruoyi.admin.service.IRewardExchangeService;
import com.ruoyi.common.core.domain.entity.Reward;
import com.ruoyi.common.core.domain.entity.RewardExchange;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 兑换记录Service业务层处理
 * 
 * @author xukai
 * @date 2024-12-22
 */
@Service
public class RewardExchangeServiceImpl implements IRewardExchangeService 
{
    @Autowired
    private RewardExchangeMapper rewardExchangeMapper;

    @Autowired
    private RewardMapper rewardMapper;


    /**
     * 查询兑换记录
     * 
     * @param id 兑换记录主键
     * @return 兑换记录
     */
    @Override
    public RewardExchange selectRewardExchangeById(Long id)
    {
        return rewardExchangeMapper.selectRewardExchangeById(id);
    }

    /**
     * 查询兑换记录列表
     * 
     * @param rewardExchange 兑换记录
     * @return 兑换记录
     */
    @Override
    public List<RewardExchangeVO> selectRewardExchangeList(RewardExchange rewardExchange)
    {
        List<RewardExchange> rewardExchanges = rewardExchangeMapper.selectRewardExchangeList(rewardExchange);
        List<RewardExchangeVO> records = rewardExchanges.stream().map(e -> {
            RewardExchangeVO rewardExchangeVO = new RewardExchangeVO();
            BeanUtils.copyProperties(e, rewardExchangeVO);
            Reward reward = rewardMapper.selectRewardById(e.getRewardId());
            rewardExchangeVO.setRewardTitle(reward.getTitle());
            return rewardExchangeVO;
        }).collect(Collectors.toList());
        return records;
    }

    /**
     * 新增兑换记录
     * 
     * @param rewardExchange 兑换记录
     * @return 结果
     */
    @Override
    public int insertRewardExchange(RewardExchange rewardExchange)
    {
        return rewardExchangeMapper.insertRewardExchange(rewardExchange);
    }

    /**
     * 修改兑换记录
     * 
     * @param rewardExchange 兑换记录
     * @return 结果
     */
    @Override
    public int updateRewardExchange(RewardExchange rewardExchange)
    {
        return rewardExchangeMapper.updateRewardExchange(rewardExchange);
    }

    /**
     * 批量删除兑换记录
     * 
     * @param ids 需要删除的兑换记录主键
     * @return 结果
     */
    @Override
    public int deleteRewardExchangeByIds(Long[] ids)
    {
        return rewardExchangeMapper.deleteRewardExchangeByIds(ids);
    }

    /**
     * 删除兑换记录信息
     * 
     * @param id 兑换记录主键
     * @return 结果
     */
    @Override
    public int deleteRewardExchangeById(Long id)
    {
        return rewardExchangeMapper.deleteRewardExchangeById(id);
    }
}
